<%-- 
    Document   : CategoryForm
    Created on : 2 févr. 2010, 22:19:44
    Author     : JC
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<%@page import="fr.uha.ensisa.kfetmanager.category.CustomerCategory"%>
<%
            String action = request.getParameter("action");
            if (action == null || action.isEmpty()) {
                response.sendError(response.SC_BAD_REQUEST);
            }
            String label = "";
            Long id = Long.valueOf(-1);
            if (action.equals("edit")) {
                CustomerCategory c;
                try {
                    c = (CustomerCategory) getServletContext().getAttribute("category");
                } catch (Exception e) {
                    getServletContext().setAttribute("errorMessage", "Objet CustomerCategory null");
                    getServletContext().setAttribute("redirectTo", "/admin/categories");
                    getServletContext().getRequestDispatcher("/error.jsp").forward(request, response);
                    return;
                }
                id = c.getId();
                label = c.getLabel();
            }
%>
<hr/>
<div>
    <h4><%=action.equals("edit") ? "Edition" : "Cr&eacute;ation"%></h4>
    <form method="POST" action="<%=getServletContext().getContextPath()%>/admin/categories/<%=action%>">
        <%if (action.equals("edit")) {%>
        <input type="hidden" name="id" value="<%=id.toString()%>"/>
        <%}%>
        Label: <input type="text" name="label" value="<%=label%>"/><br/>
        <input type="submit" value="<%=action.equals("edit") ? "Sauvegarder" : "Cr&eacute;er cat&eacute;gorie"%>"/>
    </form>
    <% if (action.equals("edit")) {%>
    <p><a href="<%=getServletContext().getContextPath()%>/admin/categories/delete?id=<%=id.toString()%>">Supprimer cat&eacute;gorie</a></p>
    <%}%>
</div>
